<template>
	<!--二维码展示页面-->
	<view class="binding">
		<view>
			<!-- {{path?"二维码已绑定":"二维码未绑定"}} -->
			<image :src="path" mode="widthFix"></image>
		</view>
		<view v-if="path">
			<button @click="jcbd" class="binding-button">解绑二维码</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				path: '',
			}
		},
		onLoad() {
			var me = this;
			console.log('点击了呀')
			var me = this;
			var merchantInfo = uni.getStorageSync("merchantInfo")
			console.log("merchantInfo=" + merchantInfo.id)
			uni.request({
				url: me.$ServerUrl + '/invoice/api/qrcode/getQrcodeByMerchantId', //根据商家ID获取二维码信息
				data: {
					"merchantId": merchantInfo.id
				},
				header: {
					'content-type': 'application/x-www-form-urlencoded' // 默认值JSON格式
				},
				method: "GET",
				success: (res) => {
					console.log(JSON.stringify(res))
					if (res.data.id) {
						//有绑定二维码
						console.log('有绑定二维码')
						me.path = me.$ServerUrl + res.data.path

						uni.setStorageSync('qrcodeId', res.data.id); //缓存 二维码id

					} else {
						//没有绑定二维码
						console.log('没有绑定二维码')
						uni.showModal({
							title: '没有绑定二维码',
							content: '请绑定商家二维码',
							success: function(res) {
								if (res.confirm) {
									console.log('用户点击确定要绑定');
									uni.redirectTo({
										url: './ewmno',
									});
								} else if (res.cancel) {
									console.log('用户点击取消');
									uni.redirectTo({
										url: '../index',
									});
								}
							}
						});
					}

				},


			})


		},
		methods: {
			jcbd() {
				var me = this;
				var qrcodeId = uni.getStorageSync('qrcodeId')
				console.log("qrcodeId陈春燕=" + qrcodeId)
				uni.request({
					url: me.$ServerUrl + '/invoice/api/qrcode/unBindingQrcode', //8080
					data: {
						"qrcodeId": qrcodeId
					},
					header: {
						'content-type': 'application/x-www-form-urlencoded' // 默认值JSON格式
					},
					method: "POST",
					success: (res) => {
						console.log(res)
						uni.showModal({
							content: '解除绑定成功',
							showCancel: false,
							success() {
								uni.redirectTo({
									url: '../index',
								})
							}
						});


					}
				});
			}
		},


	}
</script>

<style>
	.scan-result {
		min-height: 50rpx;
		line-height: 50rpx;
	}
	.binding{
		text-align: center;
		text-align: center;
		justify-content: center;
		margin-top: 50px;
	}
	.binding-button{
		margin: 20px;
		background-color: #BBBBBB;
		font-size: 16px;
	}
</style>
